<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>deleteUser</title>
</head>
<body>
     <table id="userList" border=""></table>
</body>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
<script type="text/javascript">
    $(function () {
       $.ajax({
           url:'http://localhost:63342/WWW/lr3181/getUser.php',
           type:'post',
           data:{},
           dataType:'JSON',
           success:function (data) {
               var userArr=data['userArr'];
               var num=0;
               var str='';
               if (userArr==undefined){
                    $('#userList').html('加载用户失败！');
               }else{
                   str+='<tr><th>序号</th><th>用户</th><th>操作</th></tr>';
                   for (var i = 0; i < userArr.length; i++) {
                       num++;
                       str+='<tr><td>'+num+'</td><td>'+userArr[i][1]+'</td>'+
                           '<td><a onclick=del('+userArr[i][0]+')>删除</a></td></tr>';
                   }
                   $('#userList').html(str);
               }

           },
           error:function (err) {
               alert('请求失败！');
               console.log(err);
           }
       });
    });
    function del(index) {
        $.ajax({
            url:'http://localhost:63342/WWW/lr3181/deleteUser.php',
            type:'post',
            data:{'id':index},
            dataType:'JSON',
            success:function (data) {
               if (data['result']=='delete username success'){
                    alert('删除该用户成功!');
                    window.location.reload();
               }else{
                   alert('删除用户失败!');
               }
            },
            error:function (err) {
                alert('请求失败！');
                console.log(err);
            }
        });
    }
</script>
</html>